package com.eedi.framework.logger.convert;

import cn.hutool.core.util.ObjectUtil;
import com.eedi.framework.common.util.collection.CollectionUtils;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.logger.controller.org.vo.OrgOperateLogResp;
import com.eedi.framework.logger.dal.dataobject.OrgLogOperateDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface OrgOperateLogConvert {
    OrgOperateLogConvert INSTANCE = Mappers.getMapper(OrgOperateLogConvert.class);

    default List<OrgOperateLogResp> convertList(List<OrgLogOperateDO> list) {
        return CollectionUtils.convertList(list, log -> {
            OrgOperateLogResp logVO = BeanUtils.toBean(log, OrgOperateLogResp.class);
            logVO.setName(log.getOptName());
            logVO.setOptType(log.getOptType());
            return logVO;
        });
    }

    default OrgOperateLogResp convert(OrgLogOperateDO orgLogOperateDO) {
        if (ObjectUtil.isEmpty(orgLogOperateDO)) {
            return null;
        }
        OrgOperateLogResp logVO = BeanUtils.toBean(orgLogOperateDO, OrgOperateLogResp.class);
        logVO.setName(orgLogOperateDO.getOptName());
        logVO.setOptType(orgLogOperateDO.getOptType());
        return logVO;
    }
}
